# Module for borders of fields that cannot be walked through

import pygame
import imagecache
import constants

# Uninstantiatable base class.
# Subclasses must implement the fields:
#    image_centre: where the image for the centre of a border is
#     image_connector: where the image to connect two borders is
class Border:
    def __init__(*kwargs):
        import inspect
        caller = inspect.getouterframes(inspect.currentframe())[1][3]
        raise NotImplementedError(caller + ' must be implemented in subclass')
    
    def walkable(self):
        return False
    
    def update_neighbours(self, border_list):
        image = imagecache.get_image('blank').copy()
        
        if ((self.x, self.y - 1) in border_list):
            image.blit(imagecache.get_image(self.image_connector), (0, 0))
        if ((self.x + 1, self.y) in border_list):
            image.blit(pygame.transform.rotate(imagecache.get_image(self.image_connector), 270), (0, 0))
        if ((self.x, self.y + 1) in border_list):
            image.blit(pygame.transform.rotate(imagecache.get_image(self.image_connector), 180), (0, 0))
        if ((self.x - 1, self.y) in border_list):
            image.blit(pygame.transform.rotate(imagecache.get_image(self.image_connector), 90), (0, 0))
        
        image.blit(imagecache.get_image(self.image_centre), (0,0))        
        self.image = image
    
    def get_image(self):
        return self.image


class Fence(Border):
    def __init__(self):        
        self.x = 0
        self.y = 0
        self.image = None
        
        self.image_connector = "borders/fence-bar"
        self.image_centre = "borders/fence-post"
    
    
class Wall(Border):
    def __init__(self):
        raise NotImplementedError("can't use this class yet")
        #self.image_path = "borders/wall-"
    